//
//  XHSideViewController.m
//  testApp
//
//  Created by ColdMountain on 2017/4/6.
//  Copyright © 2017年 ColdMountain. All rights reserved.
//

#import "XHSideViewController.h"

@interface XHSideViewController ()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIView *ui_sideView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *la_leftBottom;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *la_sideViewWidth;
@end

@implementation XHSideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UITapGestureRecognizer * gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onClickAction:)];
    [gesture setNumberOfTapsRequired:1];
    gesture.delegate=self;
    [self.view addGestureRecognizer:gesture];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self creatAnimation];
}

- (void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.la_sideViewWidth.constant = SCREEN_WIDTH*2/3;
    NSLog(@"%.f",self.ui_sideView.frame.size.width);
}

- (void)creatAnimation
{
    WS(weakSelf)
   [UIView animateWithDuration:0.8 animations:^{
       self.la_leftBottom.constant = 0;
       [weakSelf.view layoutIfNeeded];
   }];
}

- (void)cancelAction
{
    [self dismissViewControllerAnimated:NO completion:^{
        
    }];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    if(touch.view != self.view){
        return NO;
    }
    else
        return YES;
}
- (IBAction)onClickAction:(id)sender
{
    WS(weakSelf)
    [UIView animateWithDuration:0.8 animations:^{
        self.la_leftBottom.constant = -240;
        [weakSelf.view layoutIfNeeded];
    }];
    [self performSelector:@selector(cancelAction) withObject:nil afterDelay:1];
}
#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    
//}


#pragma - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height=0;
    return height;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
